#pragma once
#include <vector>
#include <string>
#include "micro.hxx"
using namespace std;

class Keyword
{
public:
	// typedefs
	typedef struct KeywordSeg
	{
		KeywordSeg(const std::string& segStr, size_t pos) : seg(segStr), startPos(pos){}
		size_t ValidLength(void) const 
		{
			size_t validLength = seg.length();
			for (size_t i = seg.length(); i>0; i--)
			{
				if (!isalnum(seg[i-1]))
					validLength--;
			}
			return validLength;			
		}
		std::string seg;
		size_t startPos;	// 0 means variable pos.
	};
public:
	// Constructors and Destructores
	Keyword(const string& name);

	bool IsResultQualified(const string& result) const;
	bool Is3TongTargeted(void) const;
	const string GetSpec(void) const;
	const std::vector<std::string> GetExtSpecs(void) const;

	PROPERTY(Name, std::string);

private:
	static const int KeywordLength = 5;

	std::vector<KeywordSeg> segments;

	std::string spec;

	bool Parse(void);
	static bool Compose(std::string& result, size_t keywordLen, const KeywordSeg& seg1, const KeywordSeg& seg2 = KeywordSeg("", string::npos));
};